home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / faq / wdj0597.zip / ROBBINS.ZIP / PEIMAGE.H < prev   
C/C++ Source or Header  |  1997-02-11  |  4KB  |  93 lines

  1. #ifndef _PEIMAGE_H
  2. #define _PEIMAGE_H
  3.  
  4. /*//////////////////////////////////////////////////////////////////
  5.                             Special Includes
  6. //////////////////////////////////////////////////////////////////*/
  7. #include <imagehlp.h>
  8.  
  9. /*//////////////////////////////////////////////////////////////////
  10.                           Special Enumerations
  11. //////////////////////////////////////////////////////////////////*/
  12. // These are the error enumerations that are are returned by
  13. //  various member functions of CPEImage.
  14. typedef enum _PEI_ERROR
  15. {
  16.     // Everything is good.
  17.     PEI_NOERROR     ,
  18.     // Bad parameters were passed.
  19.     PEI_BADPARAMS   ,
  20.     // The class is already initialized with an image.  Call
  21.     //  UnloadImage to unload the existing image to use this
  22.     //  instance of the class again.
  23.     PEI_ALREADYINIT ,
  24.     // The class has not been initialized.  Call LoadImage to
  25.     //  initialize it.
  26.     PEI_NOTINIT     ,
  27.     // The image could not be mapped.  Either it did not exist,
  28.     //  or it is not a WIN32 PE image.
  29.     PEI_NOTMAPPED   ,
  30. } PEI_ERROR ;
  31.  
  32. /*//////////////////////////////////////////////////////////////////
  33.                        CPEImage Class Definition
  34. //////////////////////////////////////////////////////////////////*/
  35. class CPEImage
  36. {
  37. /*//////////////////////////////////////////////////////////////////
  38.                   Public Constructors and Destructors
  39. //////////////////////////////////////////////////////////////////*/
  40. public      :
  41.     // Initializes the entire class.  Call LoadImage to do the
  42.     //  real load.
  43.     CPEImage ( void ) ;
  44.  
  45.     // The usual destructor.  It will unload the image if needed.
  46.     ~CPEImage ( void ) ;
  47.  
  48. /*//////////////////////////////////////////////////////////////////
  49.            Public Initialization and Cleanup Member Functions
  50. //////////////////////////////////////////////////////////////////*/
  51. public      :
  52.     // Loads the PE image specified in szFile (which must contain
  53.     //  the complete filename to load).
  54.     PEI_ERROR LoadImage ( LPCTSTR szFile ) ;
  55.  
  56.     // Does the opposite of LoadImage.
  57.     void UnloadImage ( void ) ;
  58.  
  59. /*//////////////////////////////////////////////////////////////////
  60.                         Public Helper Functions
  61. //////////////////////////////////////////////////////////////////*/
  62. public      :
  63.     // Converts an RVA into a pointer to the actual data.
  64.     LPCVOID ImageRvaToFileVa ( DWORD dwRVA ) const ;
  65.  
  66. /*//////////////////////////////////////////////////////////////////
  67.                  Public PE Header Information Functions
  68. //////////////////////////////////////////////////////////////////*/
  69. public      :
  70.     // Returns the PE headers.
  71.     const PIMAGE_NT_HEADERS GetImageHeaders ( void ) const ;
  72.  
  73.     // Returns the requested section header.
  74.     const PIMAGE_SECTION_HEADER
  75.                        GetSectionHeader ( int iSection ) const ;
  76.  
  77.     // Gets the particular data directory data.
  78.     DWORD GetDataDirectoryRVA ( int iDataDir ) const ;
  79.  
  80. /*//////////////////////////////////////////////////////////////
  81.                   Protected Class Data Members
  82. //////////////////////////////////////////////////////////////*/
  83. protected   :
  84.     // Internally, we use the IMAGEHLP functions to do the
  85.     //  grungy work for us.  This is the structure that is
  86.     //  returned by the MapAndLoad API call.
  87.     LOADED_IMAGE    m_stLoadedImage ;
  88. } ;
  89.  
  90. #endif      // _PEIMAGE_H
  91.  
  92.  
  93.